#include "ConfigInfo.h"
#include "Debug.h"

ConfigInfo g_ConfigInfo;

void ConfigInfo_Init(FruInfo* pFruInfo)
{
	memset(&g_ConfigInfo, 0, sizeof(ConfigInfo));

	g_ConfigInfo.m_pFruInfo = pFruInfo;
}

void ConfigInfo_AddCompactSensorRecord(CompactSensorRecord* pCompactSensorRecord)
{
	int j = 0;
	for(j = 0; j < MAX_COMPACT_SENSOR_RECORD; j++)
	{
		if(Null == g_ConfigInfo.m_pCompactSensorRecord[j])
		{
			g_ConfigInfo.m_pCompactSensorRecord[j] = pCompactSensorRecord;
			return;
		}
	}
	Assert(False);
}

void ConfigInfo_AddFullSensorRecord(FullSensorRecord* pFullSensorRecord)
{
	int j = 0;
	for(j = 0; j < MAX_FULL_SENSOR_RECORD; j++)
	{
		if(Null == g_ConfigInfo.m_pFullSensorRecord[j])
		{
			g_ConfigInfo.m_pFullSensorRecord[j] = pFullSensorRecord;
			return;
		}
	}
	Assert(False);
}

Bool ConfigInfo_Parser(ConfigInfo* pConfigInfo)
{
	int i = 0;
	const RecordHeader* pFruRecord = Null;
	uint8* pRecordData = Null;
	//ConfigInfo* pConfigInfo = &g_ConfigInfo;
	
	for(i = 0; i < MAX_RECORD_COUNT; i++)
	{
		pConfigInfo->m_isValid = True;
		pFruRecord = pConfigInfo->m_pFruInfo->m_pRecordArray[i];
		pRecordData = (uint8*)pFruRecord;

		if(Null == pFruRecord) break;
		
		if(pFruRecord->m_RecordId == COMPACT_SENSOR_RECORD)
		{
			ConfigInfo_AddCompactSensorRecord((CompactSensorRecord*)&pRecordData[10]);
			continue;
		}
		if(pFruRecord->m_RecordId == FULL_SENSOR_RECORD)
		{
			ConfigInfo_AddFullSensorRecord((FullSensorRecord*)&pRecordData[10]);
			continue;
		}
		else if(pFruRecord->m_RecordId == PET_RECORD)
		{
		}
		else
		{
			pConfigInfo->m_isValid = False;
			//Assert(False);
			break;
		}
	}	
	
	return pConfigInfo->m_isValid == True;
}

Bool ConfigInfo_Verify()
{
	if(!FruInfo_isOk(g_ConfigInfo.m_pFruInfo)) return False;
	
	ConfigInfo_Parser(&g_ConfigInfo);
	
	return g_ConfigInfo.m_isValid == True;
}



/*
void ConfigInfo_CreateSensor(ConfigInfo* pConfigInfo)
{
}
*/
